<div class="users">
  <!-- 面包屑 -->
  <el-breadcrumb class="bread" separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户列表</el-breadcrumb-item>
  </el-breadcrumb>
  <!-- 搜索框 -->
  <el-row :gutter="20">
    <el-col :span="6">
      <el-input placeholder="请输入搜索内容" v-model="searchText" class="input-with-select">
        <el-button slot="append" icon="el-icon-search" @click="searchUsers"></el-button>
      </el-input>
    </el-col>
    <el-col :span="4">
      <el-button type="success" plain @click="isAddUserForm = true">添加用户</el-button>
    </el-col>
  </el-row>
  <el-table :data="users" style="width: 100%">
    <el-table-column prop="username" label="姓名" width="180">
    </el-table-column>
    <el-table-column prop="email" label="邮箱" width="180">
    </el-table-column>
    <el-table-column prop="mobile" label="电话" width="130">
    </el-table-column>
    <el-table-column prop="mg_state" label="用户状态">
      <!-- 按钮 -->
      <template slot-scope="scope">
        <el-switch @change="changeUserStatus(scope)" v-model="scope.row.mg_state"></el-switch>
      </template>
    </el-table-column>
    <el-table-column label="操作" min-width="250">
      <template slot-scope="scope">
        <!-- 编辑 -->
        <el-button @click="showEditUser(scope)" type="primary" icon="el-icon-edit" size="mini" plain></el-button>
        <!-- 删除 -->
        <el-button @click="delUser(scope)" type="danger" icon="el-icon-delete" size="mini" plain></el-button>
        <!-- 分配角色 -->
        <el-button @click="showRolesList(scope.row)" type="success" icon="el-icon-check" size="mini" plain>分配角色</el-button>
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页 -->
  <el-pagination :current-page="pagenum" @current-change="curChange" background layout="prev, pager, next" :total="total"
    :page-size="pagesize"></el-pagination>
  <!-- `添加用户`弹框 -->
  <el-dialog title="添加用户" :visible.sync="isAddUserForm" @close="addUserFormClose">
    <el-form :model="addUserForm" :rules="rules" status-icon ref="addUserForm">
      <el-form-item label="用户名" :label-width="formLabelWidth" prop="username">
        <el-input v-model="addUserForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" :label-width="formLabelWidth" prop="password">
        <el-input v-model="addUserForm.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" :label-width="formLabelWidth" prop="email">
        <el-input v-model="addUserForm.email"></el-input>
      </el-form-item>
      <el-form-item label="手机" :label-width="formLabelWidth" prop="mobile">
        <el-input v-model="addUserForm.mobile"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="isAddUserForm = false">取 消</el-button>
      <el-button type="primary" @click="addUser">确 定</el-button>
    </div>
  </el-dialog>
  <!-- `编辑用户`弹窗 -->
  <el-dialog title="编辑用户" :visible.sync="isShowEditUserForm" @close="editUserFormClose">
    <el-form :model="editUserForm" :rules="rules" status-icon ref="editForm">
      <el-form-item label="用户名" :label-width="formLabelWidth">
        <el-tag type="info">{{ editUserForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="邮箱" :label-width="formLabelWidth" prop="email">
        <el-input v-model="editUserForm.email"></el-input>
      </el-form-item>
      <el-form-item label="手机" :label-width="formLabelWidth" prop="mobile">
        <el-input v-model="editUserForm.mobile"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="isShowEditUserForm = false">取 消</el-button>
      <el-button type="primary" @click="editUser">确 定</el-button>
    </div>
  </el-dialog>
  <!-- `分配角色`对话框` -->
  <el-dialog title="分配角色" :visible.sync="isShowAllotRolesDialog">
    <el-form ref="rolesListForm" :model="rolesListForm" label-width="80px">
      <el-form-item label="用户名">
        <el-tag type="info">{{ rolesListForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="角色列表">
        <el-select v-model="rolesListForm.rid" placeholder="请选择角色">
          <el-option v-for="item in rolesList" :key="item.id" :label="item.roleName" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="isShowAllotRolesDialog = false">取 消</el-button>
      <el-button type="primary" @click="userAllotRoles">确 定</el-button>
    </div>
  </el-dialog>
</div>